package com.example.web;

import javax.servlet.http.HttpSession;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class DemoController {
	@ResponseBody
	@RequestMapping("/applyWdc.do")
	public String demo1() {
		return "/applyWdc.do";
	}

	@ResponseBody
	@RequestMapping("/applyWdcCardSms.do")
	public String demo2() {
		return "/applyWdcCardSms.do";
	}

	@ResponseBody
	@RequestMapping("/login.do")
	public String login() {
		Subject subject = SecurityUtils.getSubject();
		subject.login(new UsernamePasswordToken("123", "123456"));
		return "/login.do";
	}

	@ResponseBody
	@RequestMapping(method = RequestMethod.POST, value = "/set")
	public String set(@RequestBody String value, HttpSession session) {
		session.setAttribute("key", value);
		return "success";
	}

	@ResponseBody
	@RequestMapping(method = RequestMethod.GET, value = "/get")
	public String get(HttpSession session) {
		return session.getAttribute("key").toString();
	}
}
